/**
 * 公用参数
 */
var name='';//就诊人姓名
var cardInfo=null
var makeInfo={}

/**
 * 默认加载
 * @type {{init: Window.process.init, public: Window.process.public}}
 */
window.process = {
    init: function () {
        this.initData();
        this.public();
    },
    initData:function () {
        var paramsData = getUrlParamsCode();
        name= paramsData['name'];
        cardInfo=JSON.parse(localStorage.getItem('cardInfo'))
        if(!!name){
            $('#name').text(cardInfo.username);
        }else{
            $('#name').text(name);
        }
        this.load()

    },
    load(){
        var api='/appVisitPays/find'
        var data={
            hos_code:cardInfo.hostcode?cardInfo.hostcode:'',
            card_no:cardInfo.cardno?cardInfo.cardno:'',
            card_type:cardInfo.cardtype?cardInfo.cardtype:'',
            start_date:getNowFormatDate(),
            end_date:get7FormatDate(1)

        }
        postAjax(api,data,this.callbackLoad,this)
    },
    callbackLoad(data,that){
        makeInfo=data
        var Data={
            list:data
        };
        var listHtml = template('list_data', Data);
        $("#list_data_content").html(listHtml);
        that.public();
    },
    callbackFrom(data,that){
        var data=data.obj
        if(paytype=='xs'){
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest', {
                    "appId":data.appId,     //公众号名称，由商户传入
                    "timeStamp":data.timeStamp,         //时间戳，自1970年以来的秒数
                    "nonceStr":data.nonceStr, //随机串
                    "package":data.package,
                    "signType":"MD5",         //微信签名方式：
                    "paySign":data.paySign //微信签名
                },
                function(res){
                    if(res.err_msg == "get_brand_wcpay_request:ok" ){

                        var data=payData[key]
                        var api='/appApponits/findpay'
                        var data={
                            regno:timestamp(),
                            cardno:data.cardno,  //传空
                            cardtype:data.cardtype, //传空
                            idcard:data.idcard,
                            idcardtype:data.idcardtype,
                            hisregno:data.hisregno


                        }
                        postAjax(api,data,that.callbackPay,that)

                    }else{
                        $.alert({
                            title: '订单成功',
                            text: '待支付，请在一分钟内完成支付',
                            onOK: function () {
                                window.location.href='../index.html'
                            }
                        });
                    }
                });
        }else{
            $.alert('到院支付')
        }
    },
    callbackPay(data){
        $.alert({
            title: '提示',
            text: data,
            onOK: function () {
                window.location.href='make_success.html'
            }
        });
    },
    public: function () {
        //进入详情
        $('#list_data_content .item').click(function () {
            localStorage.setItem("makeInfo", JSON.stringify(makeInfo));
            window.location.href="payment_detail.html";

        })
       //支付
        $('.btns').click(function () {
            var api='/appApponits/add'
            var data={
                openid:localStorage.openid,
                responsetype:localStorage.responsetype,
                regno:timestamp(),
                hoscode:payment.hostcode,
                cardno:cardInfo.cardno,  //传空
                cardtype:cardInfo.cardtype, //传空
                patientname:name,
                idcard:cardInfo.idcard,
                idcardtype:cardInfo.idcardtype,
                pidtype:'wxzf',
                paytype:'mzjf',
                paystaus:payment.paystaus,
                feestatus:payment.feestatus
            }
            postAjax(api,data,this.callbackFrom,this)
        });

    }
};

/**
 * 启动方法执行
 */
process.init();



